home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_db.idb / usr / freeware / include / db_cxx.h.z / db_cxx.h
Encoding:
C/C++ Source or Header  |  1999-04-16  |  23.8 KB  |  862 lines

  1. /*-
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1997, 1998
  5.  *    Sleepycat Software.  All rights reserved.
  6.  *
  7.  *    @(#)db_cxx.h    10.30 (Sleepycat) 11/22/98
  8.  */
  9.  
  10. #ifndef _DB_CXX_H_
  11. #define _DB_CXX_H_
  12. //
  13. // C++ assumptions:
  14. //
  15. // To ensure portability to many platforms, both new and old, we make
  16. // few assumptions about the C++ compiler and library.  For example,
  17. // we do not expect STL, templates or namespaces to be available.  The
  18. // "newest" C++ feature used is exceptions, which are used liberally
  19. // to transmit error information.  Even the use of exceptions can be
  20. // disabled at runtime, see setErrorModel().
  21. //
  22. // C++ naming conventions:
  23. //
  24. //  - All top level class names start with Db.
  25. //  - All class members start with lower case letter.
  26. //  - All private data members are suffixed with underscore.
  27. //  - Use underscores to divide names into multiple words.
  28. //  - Simple data accessors are named with get_ or set_ prefix.
  29. //  - All method names are taken from names of functions in the C
  30. //    layer of db (usually by dropping a prefix like "db_").
  31. //    These methods have the same argument types and order,
  32. //    other than dropping the explicit arg that acts as "this".
  33. //
  34. // As a rule, each DbFoo object has exactly one underlying DB_FOO struct
  35. // (defined in db.h) associated with it.  In many cases, we inherit directly
  36. // from the DB_FOO structure to make this relationship explicit.  Often,
  37. // the underlying C layer allocates and deallocates these structures, so
  38. // there is no easy way to add any data to the DbFoo class.  When you see
  39. // a comment about whether data is permitted to be added, this is what
  40. // is going on.  Of course, if we need to add data to such C++ classes
  41. // in the future, we will arrange to have an indirect pointer to the
  42. // DB_FOO struct (as some of the classes already have).
  43. //
  44.  
  45.  
  46. ////////////////////////////////////////////////////////////////
  47. ////////////////////////////////////////////////////////////////
  48. //
  49. // Forward declarations
  50. //
  51.  
  52. #include <iostream.h>
  53. #include <db.h>
  54.  
  55. class Db;                                        // forward
  56. class Dbc;                                       // forward
  57. class DbEnv;                                     // forward
  58. class DbException;                               // forward
  59. class DbInfo;                                    // forward
  60. class DbLock;                                    // forward
  61. class DbLockTab;                                 // forward
  62. class DbLog;                                     // forward
  63. class DbLsn;                                     // forward
  64. class DbMpool;                                   // forward
  65. class DbMpoolFile;                               // forward
  66. class Dbt;                                       // forward
  67. class DbTxn;                                     // forward
  68. class DbTxnMgr;                                  // forward
  69.  
  70. // These classes are not defined here and should be invisible
  71. // to the user, but some compilers require forward references.
  72. // There is one for each use of the DEFINE_DB_CLASS macro.
  73.  
  74. class DbLockTabImp;
  75. class DbLogImp;
  76. class DbMpoolImp;
  77. class DbMpoolFileImp;
  78. class DbImp;
  79. class DbTxnImp;
  80. class DbTxnMgrImp;
  81.  
  82.  
  83. ////////////////////////////////////////////////////////////////
  84. ////////////////////////////////////////////////////////////////
  85. //
  86. // Mechanisms for declaring classes
  87. //
  88.  
  89. //
  90. // Every class defined in this file has an _exported next to the class name.
  91. // This is needed for WinTel machines so that the class methods can
  92. // be exported or imported in a DLL as appropriate.  Users of the DLL
  93. // use the define DB_USE_DLL.  When the DLL is built, DB_CREATE_DLL
  94. // must be defined.
  95. //
  96. #if defined(_MSC_VER)
  97.  
  98. #  if defined(DB_CREATE_DLL)
  99. #    define _exported __declspec(dllexport)      // creator of dll
  100. #  elif defined(DB_USE_DLL)
  101. #    define _exported __declspec(dllimport)      // user of dll
  102. #  else
  103. #    define _exported                            // static lib creator or user
  104. #  endif
  105.  
  106. #else
  107.  
  108. #  define _exported
  109.  
  110. #endif
  111.  
  112. // DEFINE_DB_CLASS defines an imp_ data member and imp() accessor.
  113. // The underlying type is a pointer to an opaque *Imp class, that
  114. // gets converted to the correct implementation class by the implementation.
  115. //
  116. // Since these defines use "private/public" labels, and leave the access
  117. // being "private", we always use these by convention before any data
  118. // members in the private section of a class.  Keeping them in the
  119. // private section also emphasizes that they are off limits to user code.
  120. //
  121. #define DEFINE_DB_CLASS(name) \
  122.     public: class name##Imp* imp() { return imp_; } \
  123.     public: const class name##Imp* imp() const { return imp_; } \
  124.     private: class name##Imp* imp_
  125.  
  126.  
  127. ////////////////////////////////////////////////////////////////
  128. ////////////////////////////////////////////////////////////////
  129. //
  130. // Turn off inappropriate compiler warnings
  131. //
  132.  
  133. #ifdef _MSC_VER
  134.  
  135. // These are level 4 warnings that are explicitly disabled.
  136. // With Visual C++, by default you do not see above level 3 unless
  137. // you use /W4.  But we like to compile with the highest level
  138. // warnings to catch other errors.
  139. //
  140. // 4201: nameless struct/union
  141. //       triggered by standard include file <winnt.h>
  142. //
  143. // 4514: unreferenced inline function has been removed
  144. //       certain include files in MSVC define methods that are not called
  145. //
  146. #pragma warning(disable: 4201 4514)
  147.  
  148. #endif
  149.  
  150. ////////////////////////////////////////////////////////////////
  151. ////////////////////////////////////////////////////////////////
  152. //
  153. // Exception classes
  154. //
  155.  
  156. // Almost any error in the DB library throws a DbException.
  157. // Every exception should be considered an abnormality
  158. // (e.g. bug, misuse of DB, file system error).
  159. //
  160. // NOTE: We would like to inherit from class exception and
  161. //       let it handle what(), but there are
  162. //       MSVC++ problems when <exception> is included.
  163. //
  164. class _exported DbException
  165. {
  166. public:
  167.     virtual ~DbException();
  168.     DbException(int err);
  169.     DbException(const char *description);
  170.     DbException(const char *prefix, int err);
  171.     DbException(const char *prefix1, const char *prefix2, int err);
  172.     const int get_errno();
  173.     virtual const char *what() const;
  174.  
  175.     DbException(const DbException &);
  176.     DbException &operator = (const DbException &);
  177.  
  178. private:
  179.     char *what_;
  180.     int err_;                   // errno
  181. };
  182.  
  183.  
  184. ////////////////////////////////////////////////////////////////
  185. ////////////////////////////////////////////////////////////////
  186. //
  187. // Lock classes
  188. //
  189.  
  190. class _exported DbLock
  191. {
  192.     friend class DbLockTab;
  193.  
  194. public:
  195.     DbLock();
  196.  
  197.     int put(DbLockTab *locktab);
  198.  
  199.     DbLock(const DbLock &);
  200.     DbLock &operator = (const DbLock &);
  201.  
  202. protected:
  203.     // We can add data to this class if needed
  204.     // since its contained class is not allocated by db.
  205.     // (see comment at top)
  206.  
  207.     DbLock(DB_LOCK);
  208.     DB_LOCK lock_;
  209. };
  210.  
  211. class _exported DbLockTab
  212. {
  213.     friend class DbEnv;
  214.  
  215. public:
  216.     int close();
  217.     int detect(u_int32_t flags, int atype);
  218.     int get(u_int32_t locker, u_int32_t flags, const Dbt *obj,
  219.             db_lockmode_t lock_mode, DbLock *lock);
  220.     int id(u_int32_t *idp);
  221.     int stat(DB_LOCK_STAT **statp, void *(*db_malloc)(size_t));
  222.     int vec(u_int32_t locker, u_int32_t flags, DB_LOCKREQ list[],
  223.         int nlist, DB_LOCKREQ **elistp);
  224.  
  225.     // Create or remove new locktab files
  226.     //
  227.     static int open(const char *dir, u_int32_t flags, int mode,
  228.                     DbEnv* dbenv, DbLockTab **regionp);
  229.     static int unlink(const char *dir, int force, DbEnv* dbenv);
  230.  
  231. private:
  232.     // We can add data to this class if needed
  233.     // since it is implemented via a pointer.
  234.     // (see comment at top)
  235.  
  236.     // copying not allowed
  237.     //
  238.     DbLockTab(const DbLockTab &);
  239.     DbLockTab &operator = (const DbLockTab &);
  240.  
  241.     // Note: use DbLockTab::open() or DbEnv::get_lk_info()
  242.     // to get pointers to a DbLockTab,
  243.     // and call DbLockTab::close() rather than delete to release them.
  244.     //
  245.     DbLockTab();
  246.     ~DbLockTab();
  247.  
  248.     DEFINE_DB_CLASS(DbLockTab);
  249. };
  250.  
  251.  
  252. ////////////////////////////////////////////////////////////////
  253. ////////////////////////////////////////////////////////////////
  254. //
  255. // Log classes
  256. //
  257.  
  258. class _exported DbLsn : protected DB_LSN
  259. {
  260.     friend class DbLog;          // friendship needed to cast to base class
  261.     friend class DbMpool;
  262. };
  263.  
  264. class _exported DbLog
  265. {
  266.     friend class DbEnv;
  267.  
  268. public:
  269.     int archive(char **list[], u_int32_t flags, void *(*db_malloc)(size_t));
  270.     int close();
  271.     static int compare(const DbLsn *lsn0, const DbLsn *lsn1);
  272.     int file(DbLsn *lsn, char *namep, int len);
  273.     int flush(const DbLsn *lsn);
  274.     int get(DbLsn *lsn, Dbt *data, u_int32_t flags);
  275.     int put(DbLsn *lsn, const Dbt *data, u_int32_t flags);
  276.  
  277.     // Normally these would be called register and unregister to
  278.     // parallel the C interface, but "register" is a reserved word.
  279.     //
  280.     int db_register(Db *dbp, const char *name, DBTYPE type, u_int32_t *fidp);
  281.     int db_unregister(u_int32_t fid);
  282.  
  283.     // Create or remove new log files
  284.     //
  285.     static int open(const char *dir, u_int32_t flags, int mode,
  286.                     DbEnv* dbenv, DbLog **regionp);
  287.     static int unlink(const char *dir, int force, DbEnv* dbenv);
  288.  
  289. private:
  290.     // We can add data to this class if needed
  291.     // since it is implemented via a pointer.
  292.     // (see comment at top)
  293.  
  294.     // Note: use DbLog::open() or DbEnv::get_lg_info()
  295.     // to get pointers to a DbLog,
  296.     // and call DbLog::close() rather than delete to release them.
  297.     //
  298.     DbLog();
  299.     ~DbLog();
  300.  
  301.     // no copying
  302.     DbLog(const DbLog &);
  303.     operator = (const DbLog &);
  304.  
  305.     DEFINE_DB_CLASS(DbLog);
  306. };
  307.  
  308.  
  309. ////////////////////////////////////////////////////////////////
  310. ////////////////////////////////////////////////////////////////
  311. //
  312. // Memory pool classes
  313. //
  314.  
  315. class _exported DbMpoolFile
  316. {
  317.     friend class DbEnv;
  318.  
  319. public:
  320.     int close();
  321.     int get(db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep);
  322.     int put(void *pgaddr, u_int32_t flags);
  323.     int set(void *pgaddr, u_int32_t flags);
  324.     int sync();
  325.  
  326.     static int open(DbMpool *mp, const char *file,
  327.                     u_int32_t flags, int mode, size_t pagesize,
  328.                     DB_MPOOL_FINFO *finfop, DbMpoolFile **mpf);
  329.  
  330. private:
  331.     // We can add data to this class if needed
  332.     // since it is implemented via a pointer.
  333.     // (see comment at top)
  334.  
  335.     // Note: use DbMpoolFile::open()
  336.     // to get pointers to a DbMpoolFile,
  337.     // and call DbMpoolFile::close() rather than delete to release them.
  338.     //
  339.     DbMpoolFile();
  340.  
  341.     // Shut g++ up.
  342. protected:
  343.     ~DbMpoolFile();
  344.  
  345. private:
  346.     // no copying
  347.     DbMpoolFile(const DbMpoolFile &);
  348.     operator = (const DbMpoolFile &);
  349.  
  350.     DEFINE_DB_CLASS(DbMpoolFile);
  351. };
  352.  
  353. class _exported DbMpool
  354. {
  355.     friend class DbEnv;
  356.  
  357. public:
  358.     int close();
  359.  
  360.     // access to low level interface
  361.     // Normally this would be called register to parallel
  362.     // the C interface, but "register" is a reserved word.
  363.     //
  364.     int db_register(int ftype,
  365.                     int (*pgin)(db_pgno_t pgno, void *pgaddr, DBT *pgcookie),
  366.                     int (*pgout)(db_pgno_t pgno, void *pgaddr, DBT *pgcookie));
  367.  
  368.     int stat(DB_MPOOL_STAT **gsp, DB_MPOOL_FSTAT ***fsp,
  369.              void *(*db_malloc)(size_t));
  370.     int sync(DbLsn *lsn);
  371.     int trickle(int pct, int *nwrotep);
  372.  
  373.     // Create or remove new mpool files
  374.     //
  375.     static int open(const char *dir, u_int32_t flags, int mode,
  376.                     DbEnv* dbenv, DbMpool **regionp);
  377.     static int unlink(const char *dir, int force, DbEnv* dbenv);
  378.  
  379. private:
  380.     // We can add data to this class if needed
  381.     // since it is implemented via a pointer.
  382.     // (see comment at top)
  383.  
  384.     // Note: use DbMpool::open() or DbEnv::get_mp_info()
  385.     // to get pointers to a DbMpool,
  386.     // and call DbMpool::close() rather than delete to release them.
  387.     //
  388.     DbMpool();
  389.     ~DbMpool();
  390.  
  391.     // no copying
  392.     DbMpool(const DbMpool &);
  393.     DbMpool &operator = (const DbMpool &);
  394.  
  395.     DEFINE_DB_CLASS(DbMpool);
  396. };
  397.  
  398.  
  399. ////////////////////////////////////////////////////////////////
  400. ////////////////////////////////////////////////////////////////
  401. //
  402. // Transaction classes
  403. //
  404.  
  405. class _exported DbTxnMgr
  406. {
  407.     friend class DbEnv;
  408.  
  409. public:
  410.     int begin(DbTxn *pid, DbTxn **tid);
  411.     int checkpoint(u_int32_t kbyte, u_int32_t min) const;
  412.     int close();
  413.     int stat(DB_TXN_STAT **statp, void *(*db_malloc)(size_t));
  414.  
  415.     // Create or remove new txnmgr files
  416.     //
  417.     static int open(const char *dir, u_int32_t flags, int mode,
  418.                     DbEnv* dbenv, DbTxnMgr **regionp);
  419.     static int unlink(const char *dir, int force, DbEnv* dbenv);
  420.  
  421. private:
  422.     // We can add data to this class if needed
  423.     // since it is implemented via a pointer.
  424.     // (see comment at top)
  425.  
  426.     // Note: use DbTxnMgr::open() or DbEnv::get_tx_info()
  427.     // to get pointers to a DbTxnMgr,
  428.     // and call DbTxnMgr::close() rather than delete to release them.
  429.     //
  430.     DbTxnMgr();
  431.     ~DbTxnMgr();
  432.  
  433.     // no copying
  434.     DbTxnMgr(const DbTxnMgr &);
  435.     operator = (const DbTxnMgr &);
  436.  
  437.     DEFINE_DB_CLASS(DbTxnMgr);
  438. };
  439.  
  440. class _exported DbTxn
  441. {
  442.     friend class DbTxnMgr;
  443.  
  444. public:
  445.     int abort();
  446.     int commit();
  447.     u_int32_t id();
  448.     int prepare();
  449.  
  450. private:
  451.     // We can add data to this class if needed
  452.     // since it is implemented via a pointer.
  453.     // (see comment at top)
  454.  
  455.     // Note: use DbTxnMgr::begin() to get pointers to a DbTxn,
  456.     // and call DbTxn::abort() or DbTxn::commit rather than
  457.     // delete to release them.
  458.     //
  459.     DbTxn();
  460.     ~DbTxn();
  461.  
  462.     // no copying
  463.     DbTxn(const DbTxn &);
  464.     operator = (const DbTxn &);
  465.  
  466.     DEFINE_DB_CLASS(DbTxn);
  467. };
  468.  
  469.  
  470. ////////////////////////////////////////////////////////////////
  471. ////////////////////////////////////////////////////////////////
  472. //
  473. // Application classes
  474. //
  475.  
  476. //
  477. // A set of application options - define how this application uses
  478. // the db library.
  479. //
  480. class _exported DbInfo : protected DB_INFO
  481. {
  482.     friend class DbEnv;
  483.     friend class Db;
  484.  
  485. public:
  486.     DbInfo();
  487.     ~DbInfo();
  488.  
  489.     // Byte order.
  490.     void set_lorder(int);
  491.  
  492.     // Underlying cache size.
  493.     void set_cachesize(size_t);
  494.  
  495.     // Underlying page size.
  496.     void set_pagesize(size_t);
  497.  
  498.     // Local heap allocation.
  499.     typedef void *(*db_malloc_fcn)(size_t);
  500.     void set_malloc(db_malloc_fcn);
  501.  
  502.     // Duplicate compare function.
  503.     typedef int (*dup_compare_fcn)(const DBT *, const DBT *);
  504.     void set_dup_compare(dup_compare_fcn);
  505.  
  506.     ////////////////////////////////////////////////////////////////
  507.     // Btree access method.
  508.  
  509.     // Maximum keys per page.
  510.     void set_bt_maxkey(int);
  511.  
  512.     // Minimum keys per page.
  513.     void set_bt_minkey(int);
  514.  
  515.     // Comparison function.
  516.     typedef int (*bt_compare_fcn)(const DBT *, const DBT *);
  517.     void set_bt_compare(bt_compare_fcn);
  518.  
  519.     // Prefix function.
  520.     typedef size_t (*bt_prefix_fcn)(const DBT *, const DBT *);
  521.     void set_bt_prefix(bt_prefix_fcn);
  522.  
  523.     ////////////////////////////////////////////////////////////////
  524.     // Hash access method.
  525.  
  526.     // Fill factor.
  527.     void set_h_ffactor(u_int32_t);
  528.  
  529.     // Number of elements.
  530.     void set_h_nelem(u_int32_t);
  531.  
  532.     // Hash function.
  533.     typedef u_int32_t (*h_hash_fcn)(const void *, u_int32_t);
  534.     void set_h_hash(h_hash_fcn);
  535.  
  536.     ////////////////////////////////////////////////////////////////
  537.     // Recno access method.
  538.  
  539.     // Fixed-length padding byte.
  540.     void set_re_pad(int);
  541.  
  542.     // Variable-length delimiting byte.
  543.     void set_re_delim(int);
  544.  
  545.     // Length for fixed-length records.
  546.     void set_re_len(u_int32_t);
  547.  
  548.     // Source file name.
  549.     void set_re_source(char *);
  550.  
  551.     // Note: some flags are set as side effects of calling
  552.     // above "set" methods.
  553.     //
  554.     void set_flags(u_int32_t);
  555.  
  556.  
  557.     // (deep) copying of this object is allowed.
  558.     //
  559.     DbInfo(const DbInfo &);
  560.     DbInfo &operator = (const DbInfo &);
  561.  
  562. private:
  563.     // We can add data to this class if needed
  564.     // since parent class is not allocated by db.
  565.     // (see comment at top)
  566. };
  567.  
  568. //
  569. // Base application class.  Provides functions for opening a database.
  570. // User of this library can use this class as a starting point for
  571. // developing a DB application - derive their application class from
  572. // this one, add application control logic.
  573. //
  574. // Note that if you use the default constructor, you must explicitly
  575. // call appinit() before any other db activity (e.g. opening files)
  576. //
  577. class _exported DbEnv : protected DB_ENV
  578. {
  579.     friend class DbTxnMgr;
  580.     friend class DbLog;
  581.     friend class DbLockTab;
  582.     friend class DbMpool;
  583.     friend class Db;
  584.  
  585. public:
  586.  
  587.     ~DbEnv();
  588.  
  589.     // This constructor can be used to immediately initialize the
  590.     // application with these arguments.  Do not use it if you
  591.     // need to set other parameters via the access methods.
  592.     //
  593.     DbEnv(const char *homeDir, char *const *db_config, u_int32_t flags);
  594.  
  595.     // Use this constructor if you wish to *delay* the initialization
  596.     // of the db library.  This is useful if you need to set
  597.     // any particular parameters via the access methods below.
  598.     // Then call appinit() to complete the initialization.
  599.     //
  600.     DbEnv();
  601.  
  602.     // Used in conjunction with the default constructor to
  603.     // complete the initialization of the db library.
  604.     //
  605.     int appinit(const char *homeDir, char *const *db_config, u_int32_t flags);
  606.  
  607.     // Called automatically when DbEnv is destroyed, or can be
  608.     // called at any time to shut down Db.
  609.     //
  610.     int appexit();
  611.  
  612.     // Version information.  A static method so it can be obtained anytime.
  613.     //
  614.     static char *version(int *major, int *minor, int *patch);
  615.  
  616.     ////////////////////////////////////////////////////////////////
  617.     // simple get/set access methods
  618.     //
  619.     // If you are calling set_ methods, you need to
  620.     // use the default constructor along with appinit().
  621.  
  622.     // Byte order.
  623.     void set_lorder(int);
  624.  
  625.     // Panic callback.
  626.     typedef void (*db_paniccall_fcn)(DbEnv *, int);
  627.     void set_paniccall(db_paniccall_fcn);
  628.  
  629.     // Error message callback.
  630.     typedef void (*db_errcall_fcn)(const char *, char *);
  631.     void set_errcall(db_errcall_fcn);
  632.  
  633.     // Error message file stream.
  634.     void set_errfile(FILE *);
  635.  
  636.     // Error message prefix.
  637.     void set_errpfx(const char *);
  638.  
  639.     // Generate debugging messages.
  640.     void set_verbose(int);
  641.  
  642.     ////////////////////////////////////////////////////////////////
  643.     // Locking.
  644.  
  645.     // Return from lock_open().
  646.     DbLockTab *get_lk_info() const;
  647.  
  648.     // Two dimensional conflict matrix.
  649.     void set_lk_conflicts(u_int8_t *);
  650.  
  651.     // Number of lock modes in table.
  652.     void set_lk_modes(int);
  653.  
  654.     // Maximum number of locks.
  655.     void set_lk_max(u_int32_t);
  656.  
  657.     // Deadlock detect on every conflict.
  658.     void set_lk_detect(u_int32_t);
  659.  
  660.  
  661.     ////////////////////////////////////////////////////////////////
  662.     // Logging.
  663.  
  664.     // Return from log_open().
  665.     DbLog *get_lg_info() const;
  666.  
  667.     // Maximum file size.
  668.     void set_lg_max(u_int32_t);
  669.  
  670.  
  671.     ////////////////////////////////////////////////////////////////
  672.     // Memory pool.
  673.  
  674.     // Return from memp_open().
  675.     DbMpool *get_mp_info() const;
  676.  
  677.     // Maximum file size for mmap.
  678.     void set_mp_mmapsize(size_t);
  679.  
  680.     // Bytes in the mpool cache.
  681.     void set_mp_size(size_t);
  682.  
  683.  
  684.     ////////////////////////////////////////////////////////////////
  685.     // Transactions.
  686.  
  687.     // Return from txn_open().
  688.     DbTxnMgr *get_tx_info() const;
  689.  
  690.     // Maximum number of transactions.
  691.     void set_tx_max(u_int32_t);
  692.  
  693.     // Dispatch function for recovery.
  694.     typedef int (*tx_recover_fcn)(DB_LOG *, DBT *, DB_LSN *, int, void *);
  695.     void set_tx_recover(tx_recover_fcn);
  696.  
  697.     // Flags.
  698.     void set_flags(u_int32_t);
  699.  
  700.     ////////////////////////////////////////////////////////////////
  701.     // The default error model is to throw an exception whenever
  702.     // an error occurs.  This generally allows for cleaner logic
  703.     // for transaction processing, as a try block can surround a
  704.     // single transaction.  Alternatively, since almost every method
  705.     // returns an error code (errno), the error model can be set to
  706.     // not throw exceptions, and instead return the appropriate code.
  707.     //
  708.     enum ErrorModel { Exception, ErrorReturn };
  709.     void set_error_model(ErrorModel);
  710.  
  711.     // If an error is detected and the error call function
  712.     // or stream is set, a message is dispatched or printed.
  713.     // If a prefix is set, each message is prefixed.
  714.     //
  715.     // You can use set_errcall() or set_errfile() above to control
  716.     // error functionality using a C model.  Alternatively, you can
  717.     // call set_error_stream() to force all errors to a C++ stream.
  718.     // It is unwise to mix these approaches.
  719.     //
  720.     void set_error_stream(class ostream*);
  721.  
  722.     // used internally
  723.     static int runtime_error(const char *caller, int err,
  724.                              int in_destructor = 0, int force_throw = 0);
  725.  
  726. private:
  727.     // We can add data to this class if needed
  728.     // since parent class is not allocated by db.
  729.     // (see comment at top)
  730.  
  731.     // no copying
  732.     DbEnv(const DbEnv &);
  733.     operator = (const DbEnv &);
  734.  
  735.     ErrorModel error_model_;
  736.     static void stream_error_function(const char *, char *);
  737.     static ostream *error_stream_;
  738. };
  739.  
  740. ////////////////////////////////////////////////////////////////
  741. ////////////////////////////////////////////////////////////////
  742. //
  743. // Table access classes
  744. //
  745.  
  746. //
  747. // Represents a database table = a set of keys with associated values.
  748. //
  749. class _exported Db
  750. {
  751.     friend class DbEnv;
  752.  
  753. public:
  754.     int close(u_int32_t flags);
  755.     int cursor(DbTxn *txnid, Dbc **cursorp, u_int32_t flags);
  756.     int del(DbTxn *txnid, Dbt *key, u_int32_t flags);
  757.     int fd(int *fdp);
  758.     int get(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags);
  759.     int join(Dbc **curslist, u_int32_t flags, Dbc **dbcp);
  760.     int put(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags);
  761.     int stat(void *sp, void *(*db_malloc)(size_t), u_int32_t flags);
  762.     int sync(u_int32_t flags);
  763.  
  764.     int get_byteswapped() const;
  765.     DBTYPE get_type() const;
  766.  
  767.     static int open(const char *fname, DBTYPE type, u_int32_t flags,
  768.                     int mode, DbEnv *dbenv, DbInfo *info, Db **dbpp);
  769.  
  770.     static int xa_open(const char *fname, DBTYPE type, u_int32_t flags,
  771.                     int mode, DbInfo *info, Db **dbpp);
  772. private:
  773.     // We can add data to this class if needed
  774.     // since it is implemented via a pointer.
  775.     // (see comment at top)
  776.  
  777.     // Note: use Db::open() to get initialize pointers to a Db,
  778.     // and call Db::close() rather than delete to release them.
  779.     Db();
  780.     ~Db();
  781.  
  782.     // no copying
  783.     Db(const Db &);
  784.     Db &operator = (const Db &);
  785.  
  786.     DEFINE_DB_CLASS(Db);
  787. };
  788.  
  789. //
  790. // A chunk of data, maybe a key or value.
  791. //
  792. class _exported Dbt : private DBT
  793. {
  794.     friend class Dbc;
  795.     friend class Db;
  796.     friend class DbLog;
  797.     friend class DbMpoolFile;
  798.     friend class DbLockTab;
  799.  
  800. public:
  801.  
  802.     // key/data
  803.     void *get_data() const;
  804.     void set_data(void *);
  805.  
  806.     // key/data length
  807.     u_int32_t get_size() const;
  808.     void set_size(u_int32_t);
  809.  
  810.     // RO: length of user buffer.
  811.     u_int32_t get_ulen() const;
  812.     void set_ulen(u_int32_t);
  813.  
  814.     // RO: get/put record length.
  815.     u_int32_t get_dlen() const;
  816.     void set_dlen(u_int32_t);
  817.  
  818.     // RO: get/put record offset.
  819.     u_int32_t get_doff() const;
  820.     void set_doff(u_int32_t);
  821.  
  822.     // flags
  823.     u_int32_t get_flags() const;
  824.     void set_flags(u_int32_t);
  825.  
  826.     Dbt(void *data, size_t size);
  827.     Dbt();
  828.     ~Dbt();
  829.     Dbt(const Dbt &);
  830.     Dbt &operator = (const Dbt &);
  831.  
  832. private:
  833.     // We can add data to this class if needed
  834.     // since parent class is not allocated by db.
  835.     // (see comment at top)
  836. };
  837.  
  838. class _exported Dbc : protected DBC
  839. {
  840.     friend class Db;
  841.  
  842. public:
  843.     int close();
  844.     int del(u_int32_t flags);
  845.     int get(Dbt* key, Dbt *data, u_int32_t flags);
  846.     int put(Dbt* key, Dbt *data, u_int32_t flags);
  847.  
  848. private:
  849.     // No data is permitted in this class (see comment at top)
  850.  
  851.     // Note: use Db::cursor() to get pointers to a Dbc,
  852.     // and call Dbc::close() rather than delete to release them.
  853.     //
  854.     Dbc();
  855.     ~Dbc();
  856.  
  857.     // no copying
  858.     Dbc(const Dbc &);
  859.     Dbc &operator = (const Dbc &);
  860. };
  861. #endif /* !_DB_CXX_H_ */
  862.